package com.fit.hibernate;

import java.io.Serializable;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.criterion.Restrictions;

import com.fit.beans.CarBean;
import com.fit.interfaces.CarI;
import com.fit.service.CarsI;

public class CarsServiceHibernate implements CarsI {

	private Session session;
	
	private StatelessSession ss;
	
	
	
	public CarsServiceHibernate(Session session) {
		super();
		this.session = session;
	}

	@Override
	public CarI save(CarI car) {
		
		return (CarI) session.get(CarBean.class, session.save(car));
	}

	@Override
	public Collection<CarI> retrive() {
		Criteria criteria = session.createCriteria(CarBean.class).add(Restrictions.eq("serviceDone", false));
		return criteria.list();
	}

	@Override
	public CarI retriveSingleCar(Serializable id) {
		
		return (CarI) session.get(CarBean.class, id);
	}

	
	public CarI editSingleCar(CarI car) {
		
		return (CarI) session.merge(car);
	}

	
//	public CarI deleteSingleCar(Serializable id) {
//		// TODO Auto-generated method stub
//		CarI car = (CarI) session.get(CarBean.class, id);
//		session.delete(car);
////		session.delete(id);
//		
//		  return car;
//	}

}
